package edu.westga.vocalengineer.audio.transforms;

import java.util.Arrays;

/**
 * Implements a chorus transform for an audio clip.
 * 
 * @author mfarmer2
 *
 */
public class ChorusTransform implements ITransform {

	protected int chorusDelay;
	protected int chorusNumber;
	
	/**
	 * Sets up a chorus transform.
	 * @param delay The delay in samples for the chorus.
	 */
	public ChorusTransform(int number, int delay) {
		chorusDelay = delay;
		chorusNumber = number;
	}
	
	/**
	 * Applies the chorus to a short buffer.
	 */
	@Override
	public short[] execute(short[] samples) {
		
		short[] filtered = new short[samples.length + (chorusDelay * chorusNumber)];
		Arrays.fill(filtered, (short)0);
		
		for(int i = 0; i < samples.length; i++) {
			for(int j = 0; j < chorusNumber; j++ ) {
				filtered[i + (j * chorusDelay)] +=  samples[i];
			}
			if(filtered[i] > samples[i]) filtered[i] = samples[i];
		}
		return filtered;
	}

}
